#ifndef _BATTLEMANAGER_H_
#define _BATTLEMANAGER_H_


#include "BattleSession.h"
#include "GamePlayer.h"

// max session
#define SESSION_CACHE_COUNT 10000 

class BattleManager : public baseSingle< BattleManager >
{
public:

	BattleManager();
	~BattleManager();

	fbool				CreatBattle( GamePlayer* player1 , GamePlayer* player2 );
	fbool				CreatBattle( fint32 ec , GamePlayer* player );
	fbool				CreatBattle( NpcCreateData* data , GamePlayer* player );

	BattleSession*		CreatSession();
	fvoid				ReleaseSession( BattleSession* session );

	BattleSession*		GetSession( GamePlayer* player );

	fvoid				Init();
	fvoid				Release();

	fvoid				RemovePlayer( GamePlayer* player );

	//fvoid				Update( freal32 delay );

protected:

	
	BattleSession*		mBattleSession[ SESSION_CACHE_COUNT ];


	// db read and write thread use.
	typedef vector< BattleSession* >::iterator FreeSessionIter;
	vector< BattleSession* >	mFreeSession;

	typedef list< BattleSession* > SessionList;
	typedef list< BattleSession* >::iterator SessionListIter;
	list< BattleSession* >		mSessionList;


	typedef map< GamePlayer* , BattleSession* > PlayerSessionMap;
	typedef map< GamePlayer* , BattleSession* >::iterator PlayerSessionMapIter;
	PlayerSessionMap		mPlayerMap;
};



extern BattleManager* gBattleManager;



#endif


